package com.stylefeng.guns.modular.app.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.app.service.IBusinessClassifyService;
import com.stylefeng.guns.modular.system.model.BusinessClassify;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-08-02 21:56:21
 */
@Controller
@RequestMapping("/businessClassify")
public class BusinessClassifyController extends BaseController {

    private String PREFIX = "/app/businessClassify/";

    @Autowired
    private IBusinessClassifyService businessClassifyService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "businessClassify.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/businessClassify_add")
    public String businessClassifyAdd() {
        return PREFIX + "businessClassify_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/businessClassify_update/{businessClassifyId}")
    public String businessClassifyUpdate(@PathVariable Integer businessClassifyId, Model model) {
        BusinessClassify businessClassify = businessClassifyService.selectById(businessClassifyId);
        model.addAttribute("item",businessClassify);
        LogObjectHolder.me().set(businessClassify);
        return PREFIX + "businessClassify_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String appid) {
    	
    	EntityWrapper<BusinessClassify> wrapper=new EntityWrapper<>();
    	wrapper.eq("app_id", appid);
        return businessClassifyService.selectList(wrapper);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BusinessClassify businessClassify) {
    	businessClassify.setCreateId("1");
    	businessClassify.setCreateTime(new Date());
    	businessClassify.setUpdateTime(new Date());
        businessClassifyService.insert(businessClassify);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer businessClassifyId) {
        businessClassifyService.deleteById(businessClassifyId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BusinessClassify businessClassify) {
        businessClassifyService.updateById(businessClassify);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{businessClassifyId}")
    @ResponseBody
    public Object detail(@PathVariable("businessClassifyId") Integer businessClassifyId) {
        return businessClassifyService.selectById(businessClassifyId);
    }
}
